<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');


$shopList = Shop::GetAllShops();

$serviceList = Service::GetAll();

//print_r($_POST['service_id']);
$staff = null;
if( $_GET['id'] != null ){
	$staff = Staff::getById( abs( intval( $_GET['id'] ) ) );
}
if ( $_POST ) {
	if( $oauthMap[31] == null){
		exit;
	}
	$staff = array();
	$staff['family_name'] = $_POST['family_name'];
	$staff['personal_name'] = $_POST['personal_name'];
	$staff['sex'] = $_POST['sex'] == 1 ? 1 : 0;
	$staff['tel_no'] = $_POST['tel_no'];
	$staff['addr'] = $_POST['addr'];
	$staff['shop_id'] = $_POST['shop_id'];
	$staff['salary'] = $_POST['salary'];
	$staff['salary_type'] = $_POST['salary_type'];
	$staff['pr'] = $_POST['pr'];
	$staff['email'] = $_POST['email'];
	if( $staff['email'] != null　&& empty($_POST['staff_id'])){
		$tempUser = Users::GetUserByEmail($staff['email']);
		if( $tempUser != null && $tempUser['status'] != Users::$STATUS_STAFF ){
			$errorMsg = " email既に使われています。 ";
			include template('/service/service_staff_index');
			exit;
		}
	}

	$shop_id = $_POST['shop_id'];
	if( $_POST['staff_id'] < 1 ){
		$staffId = Staff::Create($staff);
	}else{
		$tempUser = Users::GetUserByEmail($staff['email']);
		if( $tempUser != null && $tempUser['status'] != Users::$STATUS_STAFF ){
			$errorMsg = " email既に使われています。 ";
			include template('/service/service_staff_index');
			exit;
		}
		$staff['id'] = $_POST['staff_id'];
		Staff::Update($staff);	
	}
	
	redirect( WEB_ROOT . "/service/staffManage.php?shop_id=$shop_id" );
}



include template('/service/service_staff_index');
//include template('subscribe');*/
?>